export { Options as Component } from 'vue-property-decorator';

// 防抖点击装饰器
export function Debounce(delay: number = 300) {
  return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
    const original = descriptor.value;
    const key = Symbol('debounceTimeout');

    descriptor.value = function (...args: any[]) {
      if ((this as any)[key]) {
        return;
      }

      (this as any)[key] = true;
      const result = original.apply(this, args);

      // 如果是 Promise，等待它完成
      if (result instanceof Promise) {
        return result.finally(() => {
          setTimeout(() => {
            (this as any)[key] = false;
          }, delay);
        });
      }

      // 不是 Promise，直接延时
      setTimeout(() => {
        (this as any)[key] = false;
      }, delay);

      return result;
    };

    return descriptor;
  };
} 